package com.ljx.funchat.user.service.impl;

import com.ljx.funchat.common.utils.AssertUtil;
import com.ljx.funchat.oss.client.MinIOTemplate;
import com.ljx.funchat.oss.domain.vo.req.OssReq;
import com.ljx.funchat.oss.domain.vo.resp.OssResp;
import com.ljx.funchat.user.domain.enums.UploadTypeEnum;
import com.ljx.funchat.user.domain.vo.req.UploadUrlReq;
import com.ljx.funchat.user.service.OssService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class OssServiceImpl implements OssService {

    @Autowired
    private MinIOTemplate minIOTemplate;

    @Override
    public OssResp uploadUrl(Long uid, UploadUrlReq req) {
        UploadTypeEnum uploadTypeEnum = UploadTypeEnum.of(req.getType());
        AssertUtil.isNotEmpty(uploadTypeEnum, "上传类型错误");
        OssReq ossReq = OssReq.builder()
                .fileName(req.getFileName())
                .filePath(uploadTypeEnum.getPath())
                .uid(uid)
                .build();
        // 生成预签名的对象URL
        return minIOTemplate.getPreSignedObjectUrl(ossReq);
    }
}
